<?php
/**
 * Gold Shipping Module
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * Shipping UPS
 *
 * @category    Gold
 * @package     Gold_Cshipping
 * @copyright   Copyright (c) 2011 Gold
 * @Author $Id$
*/
class Gold_Cshipping_Block_Adminhtml_Shipping_Carrier_Ups_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
	
  /**
     * Prepare table columns
     *
     * @return Mage_Adminhtml_Block_Widget_Grid
     */
    protected function _prepareColumns()
    {
        $this->addColumn('deliveryzone', array(
            'header'    => Mage::helper('adminhtml')->__('Delivery Zone'),
            'index'     => 'title',
        ));        

        $this->addColumn('dest_zip', array(
            'header'    => Mage::helper('adminhtml')->__('Zip/Postal Code From'),
            'index'     => 'dest_zip',
        ));

        $this->addColumn('dest_zip_to', array(
            'header'    => Mage::helper('adminhtml')->__('Zip/Postal Code To'),
            'index'     => 'dest_zip_to',
        ));
        
        
        $label = Mage::getSingleton('cshipping/carrier_ups')
            ->getCode('condition_name_short', $this->getConditionName());

        $this->addColumn('condition_value', array(
            'header'    => $label,
            'index'     => 'condition_value',
        ));

        $this->addColumn('condition_value_2', array(
            'header'    => $label.' Extra',
            'index'     => 'condition_value_2',
        ));

        $this->addColumn('price', array(
            'header'    => Mage::helper('adminhtml')->__('Shipping Price'),
            'index'     => 'price',
        ));

        $this->addColumn('price_2', array(
            'header'    => Mage::helper('adminhtml')->__('Shipping Price').' Extra',
            'index'     => 'price_2',
        ));
        
        $this->addColumn('delivery_type', array(
            'header'    => Mage::helper('adminhtml')->__('Delivery Type'),
            'index'     => 'delivery_type',
        ));

        return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
    }
    
   protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('cshipping/carrier_ups_collection');
        $collection->setConditionFilter($this->getConditionName())
            ->setWebsiteFilter($this->getWebsiteId());

        $this->setCollection($collection);

        return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
    }
    
      /**
         * Website filter
         *
         * @var int
         */
        protected $_websiteId;
    
        /**
         * Condition filter
         *
         * @var string
         */
        protected $_conditionName;
    
        /**
         * Define grid properties
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
            $this->setId('shippingUpsGrid');
            $this->_exportPageSize = 10000;
        }
    
        /**
         * Set current website
         *
         * @param int $websiteId
         * @return Mage_Adminhtml_Block_Shipping_Carrier_Ups_Grid
         */
        public function setWebsiteId($websiteId)
        {
            $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
            return $this;
        }
    
        /**
         * Retrieve current website id
         *
         * @return int
         */
        public function getWebsiteId()
        {
            if (is_null($this->_websiteId)) {
                $this->_websiteId = Mage::app()->getWebsite()->getId();
            }
            return $this->_websiteId;
        }
    
        /**
         * Set current website
         *
         * @param int $websiteId
         * @return Mage_Adminhtml_Block_Shipping_Carrier_Ups_Grid
         */
        public function setConditionName($name)
        {
            $this->_conditionName = $name;
            return $this;
        }
    
        /**
         * Retrieve current website id
         *
         * @return int
         */
        public function getConditionName()
        {
            return $this->_conditionName;
    }
	
}